package cc.cc4414.cc03.sys.entity;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import java.time.LocalDateTime;
import java.util.Collection;

import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;

/**
 * <p>
 * 用户表
 * </p>
 *
 * @author cc
 * @since 2019-01-05
 */
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
@TableName("sys_user")
public class User implements UserDetails {

	private static final long serialVersionUID = 1L;

	/**
	 * 主键
	 */
	private String id;

	/**
	 * 用户名
	 */
	private String username;

	/**
	 * 密码
	 */
	private String password;

	/**
	 * 手机号
	 */
	private String mobile;

	/**
	 * 新增用户时的ip
	 */
	private String ip;

	/**
	 * 创建时间
	 */
	private LocalDateTime createTime;

	/**
	 * 状态码：0为正常，1为删除，2为禁用
	 */
	private Integer state;

	/**
	 * 昵称
	 */
	private String nickname;

	/**
	 * 头像图片文件id
	 */
	private String profilePictureFileId;

	/**
	 * 权限集合，不持久化到数据库
	 */
	@TableField(exist = false)
	private Collection<? extends GrantedAuthority> authorities;

	public static final String ID = "id";

	public static final String USERNAME = "username";

	public static final String PASSWORD = "password";

	public static final String MOBILE = "mobile";

	public static final String IP = "ip";

	public static final String CREATE_TIME = "create_time";

	public static final String STATE = "state";

	public static final String NICKNAME = "nickname";

	public static final String PROFILE_PICTURE_FILE_ID = "profile_picture_file_id";

	@Override
	public boolean isAccountNonExpired() {
		return true;
	}

	@Override
	public boolean isAccountNonLocked() {
		return true;
	}

	@Override
	public boolean isCredentialsNonExpired() {
		return true;
	}

	@Override
	public boolean isEnabled() {
		return true;
	}

}
